Don't use qdata for getting the default css style
authorMatthias Clasen <mclasen@redhat.com>
Fri, 6 May 2016 11:54:22 +0000 (07:54 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 6 May 2016 14:14:07 +0000 (10:14 -0400)
There's no point in using qdata for looking this up, since
we only ever set it on the default screen anyway.

gtk/gtkcssstaticstyle.c

index fa6041437019666f141eefd4a0edf195ed9ecb60..1d4940258fa4370ae5b8cd426075745afe18010f 100644 (file)
@@ -140,27 +140,35 @@ gtk_css_static_style_set_value (GtkCssStaticStyle *style,
     }
 }
 
+static GtkCssStyle *default_style;
+
+static void
+clear_default_style (gpointer data)
+{
+  g_set_object (&default_style, NULL);
+}
+
 GtkCssStyle *
 gtk_css_static_style_get_default (void)
 {
-  static GQuark style_quark = 0;
-  GtkSettings *settings;
-  GtkCssStyle *result;
-
-  if (style_quark == 0)
-    style_quark = g_quark_from_static_string ("gtk-default-style");
-
-  settings = gtk_settings_get_for_screen (gdk_screen_get_default ());
-  result = g_object_get_qdata (G_OBJECT (settings), style_quark);
-  if (result)
-    return result;
-
-  result = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (settings),
-                                             NULL,
-                                             NULL);
-  g_object_set_qdata_full (G_OBJECT (settings), style_quark, result, g_object_unref);
+  /* FIXME: This really depends on the screen, but we don't have
+   * a screen at hand when we call this function, and in practice,
+   * the default style is always replaced by something else
+   * before we use it.
+   */
+  if (default_style == NULL)
+    {
+      GtkSettings *settings;
+
+      settings = gtk_settings_get_default ();
+      default_style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (settings),
+                                                        NULL,
+                                                        NULL);
+      g_object_set_data_full (G_OBJECT (settings), "gtk-default-style",
+                              default_style, clear_default_style);
+    }
 
-  return result;
+  return default_style;
 }
 
 GtkCssStyle *
@@ -184,7 +192,7 @@ gtk_css_static_style_new_compute (GtkStyleProviderPrivate *provider,
 
   result->change = change;
 
-  _gtk_css_lookup_resolve (lookup, 
+  _gtk_css_lookup_resolve (lookup,
                            provider,
                            result,
                            parent);